﻿using System;
using System.Collections.Generic;
using System.Text;
using Lswweb.Model;
using Lswweb.Domain;
using Lswweb.Common;
using System.Web.UI.WebControls;

namespace Lswweb.Controls
{
    public class ProductWholesaleRuleEdit : SkinnedEditControl<ProductWholesaleRuleInfo>
    {
        private TextBox tbxMinNumber;
        private TextBox tbxMaxNumber;
        private TextBox tbxPriceRate;

        protected override void InitSkin(System.Web.UI.Control skin)
        {
            tbxMinNumber = (TextBox)skin.FindControl("tbxMinNumber");
            tbxMaxNumber = (TextBox)skin.FindControl("tbxMaxNumber");
            tbxPriceRate = (TextBox)skin.FindControl("tbxPriceRate");
        }

        protected override void Add(ProductWholesaleRuleInfo model)
        {
            ProductWholesaleRule.Insert(model);            
        }

        protected override void Update(ProductWholesaleRuleInfo model)
        {
            ProductWholesaleRule.Update(model);            
        }

        protected override ProductWholesaleRuleInfo FindById(int id)
        {
            return ProductWholesaleRule.GetWholesaleRule(id);
        }

        protected override ProductWholesaleRuleInfo ModelByFrom
        {
            get
            {
                ProductWholesaleRuleInfo entity = new ProductWholesaleRuleInfo();
               
                entity.MinNumber = tbxMinNumber.GetValue<Int32>();
                entity.MaxNumber = tbxMaxNumber.GetValue<Int32>();
                entity.PriceRate = tbxPriceRate.GetValue<Decimal>();

                return entity;
            }
            set
            {
                tbxMinNumber.SetValue(value.MinNumber);
                tbxMaxNumber.SetValue(value.MaxNumber);
                tbxPriceRate.SetValue(value.PriceRate);
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "Products/WholesaleRuleEdit.ascx"; }
        }
    }
}
